package com.yhh.weblogcommon.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhh.weblogcommon.domain.dos.TagDO;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;


/**
 * @Author Eason
 * @Date 2025-04-05 0:54
 * @PackageName:com.yhh.weblogcommon.domain.mapper
 * @ClassName: TagMapper
 * @Description: TODO
 */
public interface TagMapper extends BaseMapper<TagDO> {

    default Page<TagDO> selectPageList(long current, long size, String name, LocalDate startData,LocalDate endDate){
        //分页对象
        Page<TagDO> page=new Page<>( current, size);
        //构建查询条件
        LambdaQueryWrapper<TagDO> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(Objects.nonNull(name),TagDO::getName,name) //模糊查询
                .ge(Objects.nonNull(startData),TagDO::getCreateTime,startData) //大于等于startData
                .le(Objects.nonNull(endDate),TagDO::getCreateTime,endDate) //小于等于endDate
                .orderByDesc(TagDO::getCreateTime); //order by create_time desc

        return selectPage( page,wrapper);
    }
    //根据标签关键词模糊查询
    default List<TagDO> selectByKey(String key){
        LambdaQueryWrapper<TagDO> wrapper=new LambdaQueryWrapper<>();
        //构造模糊查询条件
        wrapper.like(TagDO::getName,key).orderByDesc(TagDO::getCreateTime);
        return selectList(wrapper);
    }

    /**
     * 根据标签 ID 批量查询
     * @param tagIds
     * @return
     */
    default List<TagDO> selectByIds(List<Long> tagIds) {
        return selectList(Wrappers.<TagDO>lambdaQuery()
                .in(TagDO::getId, tagIds));
    }


}

